<?php


namespace app\admin\controller;
use think\Controller;

class Common extends Controller
{
    const PAGE_SIZE = 12;
    const CODE_COMMON_SUCCESS  =    1;
    const CODE_COMMON_ERROR    =   -1;
    public $ControllerName = '';
    public $ActionName = '';

    protected function returnApiData($code = 1, $data = [], $msg = '' , $http_status_code = 200)
    {
        return json([
            'code' => $code,
            'data' => $data,
            'msg' => $msg
        ],$http_status_code)->send();
    }


    public function _initialize(){
        //禁止机器人访问后台
        $kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
        $kw_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';
        if(preg_match("/($kw_spiders)/i", $_SERVER['HTTP_USER_AGENT'])){
            echo 'access denied';exit();
        }
        //禁止机器人访问后台

        //获取控制器和动作
        $this->ControllerName = $this->request->controller();
        $this->ActionName = $this->request->action();
        $this->assign('ControllerName',$this->ControllerName);
        $this->assign('ActionName',$this->ActionName);

        if(!session('admin_id')){
            $thisController = $this->ControllerName;
            $thisAction = $this->ActionName;
            if($thisController == "Admin" && $thisAction == "login"){

            }else{
                $this->redirect('Admin/login');
            }
        }
    }
}